#pragma once
#include "wfx.h"

#include <vector>
#include <stack>
#include <iostream>
#include "Scanner.h"
#include "ProductionBasic.h"
#include "ParserStatus.h"

MAKE_PTR(CParser);

class CParser
{
public:
	static CParserPtr create(CScannerPtr pScanner)
	{
		return CParserPtr(new CParser(pScanner));
	}
public:
	CParser(CScannerPtr pScanner);
	~CParser();

public:
	int RegisterProduction(CProductionPtr pProduction);

	void Parse(std::istream& is);

private:
	void InitializeStatusTable();

	void InitializeParse();

	int ProcessToken(CTokenPtr pToken);



protected:
	std::vector<CProductionPtr> m_pProductions;
	std::vector<CParserStatusPtr> m_ParserStatusTable;
	std::stack<CTokenPtr> m_TokenStack;
	std::stack<int> m_StatusStack;

	CScannerPtr m_pScanner;
};